package net.lzzy.practices.repositories;

import net.lzzy.practices.entities.User;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.UUID;

/**
 * @author lzzy_cyp
 * Description
 */
public interface UserRepository extends JpaRepository<User, UUID> {
    User findUserByUserNameAndPassword(String userName, String password);
    Integer countByUserName(String userName);
    Integer countAllBy();
    List<User> findAllByOrderByUpdateTimeDesc();
    List<User> findAllByOrderByUpdateTimeDesc(Pageable pageable);
    List<User> findUserByApplyTeacherOrderByUpdateTimeDesc(boolean applying);

    @Query("select u from User u where u.userName like concat('%',:kw,'%') or u.nickName like concat('%',:kw,'%') "+
    "or u.email like concat('%',:kw,'%') or u.phone like concat('%',:kw,'%') ")
    List<User> findByQuery(@Param("kw") String kw);

    /**
     * 返回指定用户名用户的投影(salt)
     * @param userName 用户名
     * @return UserProjection
     */
    List<UserProjection> findUserByUserName(String userName);
}
